# -*- coding = utf-8 -*-
# @Time : 2021/11/1 16:49
# @Author : 刘纹石
# @File : Allcard.py
# @Software : PyCharm
import time

import pygame
import sys
from pygame.locals import *
from random import *
import traceback


def getcard():
    import Main
    bg_pic = pygame.image.load("../Docs/images/b7.jpg")
    Main.screen.blit(pygame.transform.scale(bg_pic, (1120, 630)), (0, 0))
    Main.screen.blit(bg_pic, (0, 0))

    # 设置标题
    word = "卡牌"
    word_location = (480, 20)
    font = pygame.font.Font("../Docs/images/SourceHanSerif-Light.ttc", 35)
    text = font.render(word, True, (0, 0, 0))
    Main.screen.blit(text, word_location)

    # 绘制关卡
    from PublicTools import button
    _mission = 1

    button_size = (130, 180)
    y = 75
    while y < 550:
        x = 100
        while x < 850:
            if card_show((x, y), button_size, str(_mission), 14, (x + 55, y + 65), "../Docs/images/card.jpg"):
                Main.chosen_mission = _mission
            _mission += 1
            x += 180
        y += 200
    Main.scene = 4
    if button((10, 10), (80, 45), "返回", 14, (30, 25), "../Docs/images/button3.png"):
        Main.scene = 0
    return Main.scene


def card_show(image_location, image_size, word, word_size, word_location, image):
    new_button = pygame.image.load(image)
    font = pygame.font.Font("../Docs/images/SourceHanSerif-Light.ttc", word_size)
    text = font.render(word, True, (0, 0, 0))
    changed_button = pygame.transform.scale(new_button, image_size)
    from Main import screen
    (x, y) = pygame.mouse.get_pos()
    if (x > image_location[0]) & (x < image_location[0] + image_size[0]) & (y > image_location[1]) & (
            y < image_location[1] + image_size[1]):
        changed_button1 = pygame.transform.scale(changed_button, (image_size[0] + 10, image_size[1] + 10))
        pygame.event.get()
        press_array = pygame.mouse.get_pressed()
        if press_array[0]:
            screen.blit(text, word_location)
            screen.blit(changed_button, image_location)
            while 1:
                pygame.event.get()
                press_array = pygame.mouse.get_pressed()
                if press_array[0] == 0:
                    return 1
        screen.blit(text, word_location)
        screen.blit(changed_button1, (image_location[0] - 5, image_location[1] - 5))
    else:
        screen.blit(text, word_location)
        screen.blit(changed_button, image_location)
    return 0
